<!--
 * @Description  : 
 * @Author       : 系统生成
 * @Date         : 2023-06-16 10:21:23
 * @LastEditTime : 2023-06-16 10:21:23
 * @LastEditors  : 系统生成
-->
<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <title>按钮功能设置</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE">
    <link rel="stylesheet"
        href="/seeyon/apps_res/cap/customCtrlResources/newFormDataBtnResources/css/setTargetFormInfo.css?V=STATIC_SUFFIX">
</head>

<body>
    <div class="new-btn-part new-btn-setting">
        <div class="new-btn-line">
            <span class="new-btn-left-label" style="width: 144px;" id="btnNameSpan">按钮名称:</span>
            <span id="newFormDataSpan">数据透视</span>
        </div>

        <div class="new-btn-line">
            <span class="new-btn-left-label" style="width: 144px;"><span class="nb-required">*</span><span
                    id="targetSpan">选择业务空间</span></span>
            <select class="new-btn-input js-target js-space">

            </select>
        </div>
        <div class="new-btn-line">
            <span class="new-btn-left-label" style="width: 144px;"><span class="nb-required">*</span><span
                    id="distetSpan">参数字段</span></span>
            <select class="new-btn-input js-target js-fields">

            </select>
        </div>
    </div>

    <script src="/seeyon/common/js/jquery-debug.js?V=STATIC_SUFFIX"></script>
    <script src="../../../../cap4/fieldDesign.do?method=headerJs"></script>
    <script src="/seeyon/common/cap4/common/i18n.js?V=STATIC_SUFFIX"></script>
    <script src="/seeyon/apps_res/cap/customCtrlResources/common/js/formMappedChecker.js?V=STATIC_SUFFIX"></script>


</body>

</html>
<script>
// 全局数据
var gTransParams = null; // 弹框参数
var formId = "";
var listSpace = [];
var listFields = [];
var selectedSpace = {};
var selectFields = {};

$(function () {
    initParam();

    // 国际化
    // $('#newFormDataSpan').text($.i18n('dataPivot.label'));
    // $('#targetSpan').text($.i18n('dataPivot.select.label'));
    // $('#distetSpan').text($.i18n('dataPivot.filed.label'));

    $('.js-space').change(function (e) {
        // console.log(e);
        selectedSpace.id = $(this).val();
    });

    $('.js-fields').change(function (e) {
        selectFields.id = $(this).val();
    });

});

function initData(bizId, formId) {
    var proc = top.$.progressBar();
    selectedSpace = gTransParams.params.selectedSpace || { id: -1 };
    selectFields = gTransParams.params.selectFields || { id: -1 };
    $.ajax({
        url: (window._ctxPath || top._ctxPath) + "/rest/xtc/common/request/dataPivotBtnManager/getCAPPortalSpace",// paramsObj.formBaseInfo.formBaseInfo.formInfo.id,
        type: 'post',
        dataType: 'json',
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({ formId: formId }),
        success: function (res) {
            proc.close();
            if (res.code == 200 && res.data) {
                // listSpace = res.data;
                var se = '<option value="-1"></option>'
                for (let index = 0; index < res.data.length; index++) {
                    var element = res.data[index];
                    se += '<option value=' + element.id + '>' + element.name + '</option>'
                }

                $(".js-space").append(se)
                $(".js-space").val(selectedSpace.id)

            }
        },
        error: function (err) {
            proc.close();
            top.$.alert(err.message || "服务器错误")
        }
    });

    $.ajax({
        url: (window._ctxPath || top._ctxPath) + "/rest/xtc/common/request/dataPivotBtnManager/getFormFields",// paramsObj.formBaseInfo.formBaseInfo.formInfo.id,
        type: 'post',
        dataType: 'json',
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({ formId: formId }),

        success: function (res) {
            proc.close();
            if (res.code == 200 && res.data) {
                // listSpace = res.data;
                var se = '<option value="-1"></option>';
                for (let index = 0; index < res.data.length; index++) {
                    var element = res.data[index];
                    se += '<option value=' + element.id + '>' + element.display + '</option>'
                }

                $(".js-fields").append(se)
                $(".js-fields").val(selectFields.id)
            }
        },
        error: function () {
            proc.close();
            top.$.alert(err.message || "服务器错误")
        }
    });
}


function initParam() {
    var obj = window.parentDialogObj && window.parentDialogObj["ctrlDialog"];
    if (obj) {
        gTransParams = obj.getTransParams();
        formId = gTransParams.formBaseInfo.formBaseInfo.formInfo.id;
        initData(gTransParams.formBaseInfo.bizConfigId, gTransParams.formBaseInfo.formBaseInfo.formInfo.id)
    }
}

/**
*
* 控件弹框返回参数就是控件自身的参数可以
*
*/
function OK() {

    if (!selectedSpace.id || selectedSpace.id == -1) {
        top.$.alert("请选择业务空间!")
        return { valid: false }
    }

    if (!selectFields.id || selectFields.id == -1) {
        top.$.alert("请选择参数字段!")
        return { valid: false }
    }

    return {
        valid: true,
        data: {
            formId: formId,
            selectedSpace: selectedSpace,
            selectFields: selectFields,
        }
    }
}

</script>
